package  com.rboat.exam.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.rboat.common.annotation.Log;
import com.rboat.common.enums.BusinessType;
import com.rboat.exam.domain.ExamTestPaper;
import com.rboat.exam.service.IExamTestPaperService;
import com.rboat.common.core.controller.BaseController;
import com.rboat.common.core.domain.AjaxResult;
import com.rboat.common.utils.poi.ExcelUtil;
import com.rboat.common.core.page.TableDataInfo;

/**
 * 试卷Controller
 * 
 * @author rboat
 * @date 2019-09-02
 */
@Controller
@RequestMapping("/exam/paper")
public class ExamTestPaperController extends BaseController
{
    private String prefix = "exam/paper";

    @Autowired
    private IExamTestPaperService examTestPaperService;

    @RequiresPermissions("exam:paper:view")
    @GetMapping()
    public String paper()
    {
        return prefix + "/paper";
    }

    /**
     * 查询试卷列表
     */
    @RequiresPermissions("exam:paper:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamTestPaper examTestPaper)
    {
        startPage();
        List<ExamTestPaper> list = examTestPaperService.selectExamTestPaperList(examTestPaper);
        return getDataTable(list);
    }

    /**
     * 导出试卷列表
     */
    @RequiresPermissions("exam:paper:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamTestPaper examTestPaper)
    {
        List<ExamTestPaper> list = examTestPaperService.selectExamTestPaperList(examTestPaper);
        ExcelUtil<ExamTestPaper> util = new ExcelUtil<ExamTestPaper>(ExamTestPaper.class);
        return util.exportExcel(list, "paper");
    }

    /**
     * 新增试卷
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存试卷
     */
    @RequiresPermissions("exam:paper:add")
    @Log(title = "试卷", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamTestPaper examTestPaper)
    {
        return toAjax(examTestPaperService.insertExamTestPaper(examTestPaper));
    }

    /**
     * 修改试卷
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ExamTestPaper examTestPaper = examTestPaperService.selectExamTestPaperById(id);
        mmap.put("examTestPaper", examTestPaper);
        return prefix + "/edit";
    }

    /**
     * 修改保存试卷
     */
    @RequiresPermissions("exam:paper:edit")
    @Log(title = "试卷", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamTestPaper examTestPaper)
    {
        return toAjax(examTestPaperService.updateExamTestPaper(examTestPaper));
    }

    /**
     * 删除试卷
     */
    @RequiresPermissions("exam:paper:remove")
    @Log(title = "试卷", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examTestPaperService.deleteExamTestPaperByIds(ids));
    }
}
